package edu.gatech.cs2340.group7.wheresmystuffapp.presenters;

import edu.gatech.cs2340.group7.wheresmystuffapp.model.DatabaseHelper;
import edu.gatech.cs2340.group7.wheresmystuffapp.views.DeleteAccountView;
/**
 * All of the logic for the account deletion process
 * @author Magic 7
 *
 */
public class DeleteAccountPresenter {
	private DeleteAccountView myView;
	private DatabaseHelper helper;

	public DeleteAccountPresenter(DeleteAccountView view) {
		this.myView = view;
		helper = new DatabaseHelper(myView);
	}

	/**
	 * Deletes an account from the database.
	 * 
	 * @param username
	 *            Username of account to be deleted
	 */
	public void deleteUser(String username) {
		if (username.isEmpty()) {
			myView.setDeleteResultText("Username invalid");
		} else if (!helper.accountExists(username)) {
			myView.setDeleteResultText("Username not Found");
		} else {
			boolean removed = helper.deleteAccount(username);

			if (removed == true) {
				myView.setDeleteResultText("Account for " + username
						+ " deleted");
			} else {
				myView.setDeleteResultText("Account for " + username
						+ " not deleted");
			}
		}
	}
}
